<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>我发布的</title>
    <<meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/static/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/css/sm.min.css">
    <link rel="stylesheet" href="/static/css/sm-extend.min.css">

    <!--icon css-->
    <!--<link rel="stylesheet" href="css/icon-style.css">-->


    <!--重写css-->
    <style>
        .tc{
            width: 100%;
            height: 2rem;
        }
        .commodityStatus{
            border: solid .2rem red;color: red;font-weight: 800;
            transform:rotate(-8deg);
            -ms-transform:rotate(-8deg); 	/* IE 9 */
            -moz-transform:rotate(-8deg); 	/* Firefox */
            -webkit-transform:rotate(-8deg); /* Safari 和 Chrome */
            -o-transform:rotate(-8deg); 	/* Opera */
        }

    </style>
</head>

<body>
<!--头部-->
<header class="bar bar-nav">
    <a class="icon icon-left pull-left" href="JavaScript:history.back(-1)"></a>
    <h1 class="title">我发布的</h1>
</header>

<!-- 内容区-->
<div class="content">

</div>


<script type='text/javascript' src='/static/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/js/sm-extend.min.js' charset='utf-8'></script>
<script type="text/javascript" src="/static/js/deatilPage.js" charset="utf-8"></script>
<script>
$(document).ready(function () {
    $.ajax({
        type: "get",
        url: "/setting/detail",
        dataType: "json",
        success: function (re) {
            if (!re.status) {
                var data = re.data.iProductList.data;
                if (!data.length){
                    $.toast("您还没有发布过商品！");
                    $('.content').append("<p class=\"text-center\">您还没有发布过商品</p>");
                }else {
                    var result = '';
                    for (var i = 0;i<data.length;i++){
                        var star = new Array();//新建一个数组，
                        star = data[i].goodImg.split(',');//分割图片
                        result+=
                            "<div class=\"card\">\n" +
                            "        <div class=\"card-header\">\n" +
                            "            <div class=\"item-media\" style=\"width: 70%\">\n" +
                            "                <img src=\""+star[0]+"\" width=\"44\" style=\"border-radius: 5px;margin-right:0.5rem;float: left\">\n" +
                            "                <div class=\"item-title\" >\n" +
                            "                    <span>"+data[i].name+"</span><br>\n" +
                            "                    <span style=\"font-size: 0.4rem!important; color: red\">￥"+data[i].price+"</span>\n" +
                            "                </div>\n" +
                            "            </div>\n" ;
                                if(data[i].status == 2){
                                    result+= "<div class=\"item-inner\">\n" +
                                        "                <div class=\"commodityStatus\">\n" +
                                        "                    已卖出\n" +
                                        "                </div>\n" +
                                        "            </div>"+
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"pull-right\" ><span class=\"icon icon-remove\" data-id='"+data[i].goodId+"' data-status='"+data[i].status+"'></span> </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>"
                                }else if (data[i].status == 1){
                                    result+= "<div class=\"item-inner\">\n" +
                                        "                <div class=\"commodityStatus\">\n" +
                                        "                    已下架\n" +
                                        "                </div>\n" +
                                        "            </div>"+
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"pull-right\" ><span class=\"icon icon-remove\" data-id='"+data[i].goodId+"' data-status='"+data[i].status+"'></span> </div>\n" +
                                        "                <div class=\"button button-light pull-right\" style=\"margin-right: .5rem\" onclick=\"reAdd("+data[i].goodId+") \">重新上架</div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>"
                                }else {
                                    result+=
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"pull-right\" ><span class=\"icon icon-remove\" data-id='"+data[i].goodId+"' data-status='"+data[i].status+"'></span> </div>\n" +
                                        "                <div class=\"button button-light pull-right\" style=\"margin-right: .5rem\" onclick=\"updateGood("+data[i].goodId+") \">编辑</div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>"
                                }

                    }
                    $('.content').append(result);
                }
            }else {
                $.toast(re.msg);
            }
        }
    });

    $(document).on('click', '.icon-remove',function (remove) {
        var remove = $(this);
        var goodId = remove.attr('data-id');
        var status = remove.attr('data-status');
        if (status == 1){
            $.toast('该商品已经下架了');
        }else if (status == 2){
            $.toast('该商品已经卖出了');
        }else {
            $.confirm('确定下架该商品吗?',
                function () {
                var myStatus = 1;
                    $.ajax({
                        type: "post",
                        url: "/sys/good/updateStatusByMyself",
                        data: {goodId: goodId, status: myStatus},
                        dataType: "json",
                        success: function (re) {
                            if (!re.status) {
                                $.toast(re.msg);
                                remove.parents('.card').remove();
                            } else {
                                $.toast(re.msg);
                            }
                        }
                    });
                },
                function () {

                }
            );
        }
    });
});

//编辑商品
function updateGood() {

}
//重新上架商品
function reAdd(id) {
    $.confirm('确定重新上架该商品吗?',
        function () {
            var myStatus = 0;
            $.ajax({
                type: "post",
                url: "/sys/good/updateStatusByMyself",
                data: {goodId: id,status:myStatus},
                dataType: "json",
                success: function (re) {
                    if (!re.status) {
                        $.toast('上架成功');
                        window.location.reload();
                    } else {
                        $.toast(re.msg);
                    }
                }
            });
        },function () {
            //取消
        })
}
</script>
</body>

</html>